package main

import "fmt"

type User struct {
	name string
	age  int
}

// 方法接收器
func (u User) SetName(name string) {
	u.name = name
}

func (u *User) SetNamePtr(name string) {
	u.name = name
}

func main() {
	u1 := User{
		name: "lkm",
		age:  21,
	}
	fmt.Printf("%+v\n", u1)

	u2 := &User{
		name: "雷康明",
		age:  21,
	}
	fmt.Printf("%+v\n", u2)

	u3 := new(User)
	fmt.Printf("%+v\n", u3)

	u4 := User{}
	u4.SetName("康明") //值传递
	fmt.Printf("%+v\n", u4)
	u4.SetNamePtr("雷康明") //这样才能改变外面的值
	fmt.Printf("%+v\n", u4)

}
